package com.apes.fico.masterdata.gl.respository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.fico.masterdata.gl.model.AccountingChart;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

public interface AccountingChartRepository extends CustomRepository<AccountingChart, String> {
    @Query("select T from AccountingChart T where T.accSystem.id =:value  order by T.id")
    List<AccountingChart> findAllByAccSystem_Id(@Param("value") String id);

    @Query("select  T from AccountingChart T where T.code=:value")
    AccountingChart findAllByCode(@Param("value") String Code);

    @Query("select new map(T.id as id,T.code as code ,T.name as name, T.finalFlag as finalFlag) from AccountingChart T where T.accSystem.id=:value  order by T.id")
    List<Map<String, String>> findByAccSystem_Id(@Param("value") String accSystem);

    @Query("select new map(T.id as id,T.code as code,T.name as name, T.finalFlag as finalFlag) from AccountingChart T where T.accGroup.id=:accGroup and T.accSystem.id=:accSystem order by T.id")
    List<Map<String, String>> findByAccGroup_IdAndAccSystem_Id(@Param("accGroup") String accGroup, @Param("accSystem") String accSystem);

    @Query("select T from AccountingChart T where 1=1 and (T.code like :value% and T.accSystem.id =:accSystem and T.classes =:classes)  order by T.id")
    List<AccountingChart> findAllByCodeAndAccSystemAndClasses(@Param("value") String code, @Param("accSystem") String accSystem, @Param("classes") double classes);

}
